feat: add view-based filtering support for sheet writing#925
Open
bengbengbalabalabeng wants to merge 7 commits into
Open
feat: add view-based filtering support for sheet writing#925bengbengbalabalabeng wants to merge 7 commits into
bengbengbalabalabeng wants to merge 7 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds view-based column filtering for sheet writing (Closed: #854) by introducing a new @ExcelView annotation and a groups(...) API on the writer builder to select fields by type-based or string-based “view” identifiers, integrating the view filter into the existing write-time ignore/include/exclude pipeline. It also adds unit/integration tests to validate header output across XLS/XLSX/CSV.
Changes:
- Introduces
@ExcelViewplus view matchers (WriteViewMatcher, class-based, name-based, and default/noop) to decide which fields are exported. - Extends the writer builder with
groups(Class<?>...)andgroups(String...)to activate view filtering. - Adds tests covering typed/name/mixed view scenarios and updates
ClassUtilsTestto account for the new write-holder matcher dependency.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| fesod-sheet/src/main/java/org/apache/fesod/sheet/annotation/write/ExcelView.java | Adds @ExcelView annotation used to tag fields with view identifiers for write-time filtering. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/util/ClassUtils.java | Integrates view filtering into field discovery/ignore logic and caches the matcher in the cache key. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/write/builder/AbstractExcelWriterParameterBuilder.java | Adds groups(...) APIs that set the active view matcher for a write operation. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/write/metadata/WriteBasicParameter.java | Adds writeViewMatcher parameter to carry view selection through writer configuration. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/write/metadata/holder/WriteHolder.java | Exposes writeViewMatcher() to downstream write logic. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/write/metadata/holder/AbstractWriteHolder.java | Initializes/inherits writeViewMatcher (defaults to noop). |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/write/view/WriteViewMatcher.java | Defines the strategy interface for write-time view matching. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/write/view/NoopWriteViewMatcher.java | Provides the default matcher used when no views are configured. |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/write/view/NameBasedViewMatcher.java | Implements string-based view matching via @ExcelView(asNames=...). |
| fesod-sheet/src/main/java/org/apache/fesod/sheet/write/view/ClassBasedViewMatcher.java | Implements type-based view matching via @ExcelView(asTypes=...). |
| fesod-sheet/src/test/java/org/apache/fesod/sheet/util/ClassUtilsTest.java | Updates existing field-cache tests and adds new tests for typed/named view filtering. |
| fesod-sheet/src/test/java/org/apache/fesod/sheet/view/WriteSheetViewTests.java | Adds end-to-end header verification tests across XLS/XLSX/CSV for view filtering behavior. |
| fesod-sheet/src/test/java/org/apache/fesod/sheet/view/WriteViewStrategy.java | Test-only view marker types used by typed view tests. |
| fesod-sheet/src/test/java/org/apache/fesod/sheet/view/WriteTypedViewsData.java | Test data model using @ExcelView(asTypes=...). |
| fesod-sheet/src/test/java/org/apache/fesod/sheet/view/WriteNamedViewsData.java | Test data model using @ExcelView(asNames=...). |
| fesod-sheet/src/test/java/org/apache/fesod/sheet/view/WriteMixedViewData.java | Test data model combining both asTypes and asNames, plus an unannotated field. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+22
to
+26
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Inherited; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; |
Comment on lines
+48
to
+51
| @Target(ElementType.FIELD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Inherited | ||
| public @interface ExcelView { |
Comment on lines
+53
to
+57
| /** | ||
| * View or views that annotated element is part of. Views are identified | ||
| * by classes, and use expected class inheritance relationship: child | ||
| * views contain all elements parent views have. | ||
| */ |
Comment on lines
+57
to
+59
| return Arrays.stream(fieldGroups).anyMatch(fieldGroup -> expectedGroups.stream() | ||
| .anyMatch(expectedGroup -> expectedGroup.isAssignableFrom(fieldGroup))); | ||
| } |
Comment on lines
+57
to
+59
| return Arrays.stream(fieldGroups).anyMatch(fieldGroup -> expectedGroups.stream() | ||
| .anyMatch(expectedGroup -> expectedGroup.equals(fieldGroup))); | ||
| } |
Comment on lines
+183
to
+186
| public T groups(Class<?>... types) { | ||
| parameter().setWriteViewMatcher(new ClassBasedViewMatcher(Arrays.asList(types))); | ||
| return self(); | ||
| } |
Comment on lines
+194
to
+197
| public T groups(String... names) { | ||
| parameter().setWriteViewMatcher(new NameBasedViewMatcher(Arrays.asList(names))); | ||
| return self(); | ||
| } |
Comment on lines
+58
to
+61
| void setUp(@TempDir Path tempDir) { | ||
| write03 = createTmpFile(tempDir, "write03.xls"); | ||
| write07 = createTmpFile(tempDir, "write07.xls"); | ||
| writeCsv = createTmpFile(tempDir, "writeCsv.csv"); |
Comment on lines
+38
to
+41
| @Override | ||
| public boolean matches(Field field) { | ||
| return false; | ||
| } |
- Remove @inherited meta-annotation in @ExcelView - Correct the javadoc of ExcelView#asTypes - Refine WriteViewMatcher parameter validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose of the pull request
Closed: #854
What's changed?
For usage examples, please refer to: Proposal
@ExcelViewto handle View-based filtering logic, supporting both Type-based and String-based modes throughasTypesandasNames.fesod-sheet.Filtering Priority:
Checklist